package com.ellfors.module_first.snap

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import com.ellfors.common.base.adapter.BaseSingleAdapter
import com.ellfors.common.ext.bindPage
import com.ellfors.module_first.R
import com.ellfors.module_first.databinding.ItemSnapBinding

class SnapAdapter : BaseSingleAdapter<String, ItemSnapBinding>() {

    private val mData: MutableList<String> = arrayListOf()

    init {
        for (i in 0..20) {
            mData.add("Position $i")
        }
        submitList(mData)
    }

    override val initViewBinding: (LayoutInflater, ViewGroup, Boolean) -> ItemSnapBinding
        get() = ItemSnapBinding::inflate

    override fun convert(holder: SingleViewHolder<ItemSnapBinding>, position: Int, item: String?) {
        holder.binding.cvTest.bindPage { ItemSnap(item) }
    }

    @Composable
    fun ItemSnap(str: String?) {
        Row(
            horizontalArrangement = Arrangement.Center,
            verticalAlignment = Alignment.CenterVertically,
            modifier = Modifier
                .fillMaxWidth()
                .fillMaxHeight()
                .background(colorResource(id = R.color.purple_200))
        ) {
            Text(
                text = str ?: ""
            )
        }
    }
}